package com.summer.data.table.column;

import com.summer.data.jql.behavior.FilterAble;
import com.summer.data.jql.concept.exp.FixedLikeFilterExp;
import com.summer.data.jql.concept.exp.LeftLikeFilterExp;
import com.summer.data.jql.concept.exp.LikeFilterExp;
import com.summer.data.jql.concept.exp.RightLikeFilterExp;
import com.summer.data.table.BaseColumn;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 *
 * @param format
 *               xx% 左部一致模糊查询 -&gt; ?%
 *               %xx 右部一致模糊查询 -&gt; %?
 *               %xx% 左右全模糊查询 -&gt; %?%
 *               xx_ 左部一致模糊查询 -&gt; ?_
 *               _xx 右部一致模糊查询 -&gt; _?
 *               _xx_ 左右全模糊查询 -&gt; _?_
 * @param value  value
 * @return FilterAble
 */
/**
 * @author 345480567@qq.com
 */

public class StringColumn extends BaseColumn<String> {

    public StringColumn(String colName) {
        super(colName);
    }

//    public StringColumn(String colName, Object entity) {
//        super(colName, entity);
//    }

    @Override
    public boolean isNeedInsert() {
        return value != null && !value.isEmpty();
    }

    @Override
    public void fetchNotNullValue(ResultSet resultSet, Integer index) throws SQLException {
        value = getValue(resultSet, index);
    }

    public static String getValue(ResultSet resultSet, Integer index) throws SQLException {
        return resultSet.getString(index);
    }

    public FilterAble like(String param) {
        return new LikeFilterExp(this, param);
    }

    public FilterAble leftLike(String value) {
        return new LeftLikeFilterExp(this, value);
    }

    public FilterAble rightLike(String value) {
        return new RightLikeFilterExp(this, value);
    }

    public FilterAble fixedLike(int leftFix, String param, int rightFix) {
        return new FixedLikeFilterExp(this, param, leftFix, rightFix);
    }

}
